//////////////////////////////////////////////////////////////////////////
//
// Vector Graph Core2D
//
// Module:
//        Break2D.cs
//
// Description:
//        Implementation of break operation
//
// Author:
//        Created on 2008.04.18 by Destrayer
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;

namespace VectorGraph.Core2D
{
    class Break2D
    {
        public static bool BreakAt(Segment2d seg, Point2d breakPt, out Segment2d part1, out Segment2d part2)
        {
            part1 = seg;
            part2 = seg;
            if (breakPt.Equals(seg.StartPt, Element2D.Precition) || breakPt.Equals(seg.EndPt, Element2D.Precition))
            {
                return false;
            }
            part1.EndPt = breakPt;
            part2.StartPt = breakPt;
            return true;
        }

        public static bool Break(Segment2d seg, Point2d breakPt, out Segment2d part1, out Segment2d part2)
        {
            return Break2D.BreakAt(seg, ClosestPoint2D.ClosestPoint(seg, breakPt), out part1, out part2);
        }

        public static bool Break(Arc2d arc, Point2d breakPt, out Arc2d part1, out Arc2d part2)
        {
            part1 = arc;
            part2 = arc;
            breakPt -= arc.CenterPt;
            if (arc.StartVector.SweepAngle(breakPt) > arc.SweepAngle - Element2D.Precition)
            {
                return false;
            }
            breakPt.Scale(arc.Radius / breakPt.Length);
            part1.EndVector = breakPt;
            part2.EndVector = breakPt;
            return true;
        }
    }
}
